import { FC, useEffect } from 'react'
import { Form, Input } from 'antd'
import { propsType } from './index'
import { useDispatch } from 'react-redux'
import { editComponent } from '@/store/componentsReducer'
const PropComponent: FC<propsType> = props => {
  const { text, placeholder, disabled } = props
  const [form] = Form.useForm()
  const dispatch = useDispatch()
  useEffect(() => {
    form.setFieldsValue({ text, placeholder })
  }, [text, placeholder, form])
  const handelValueChange = () => {
    dispatch(editComponent(form.getFieldsValue()))
  }
  return (
    <Form
      onValuesChange={handelValueChange}
      disabled={disabled}
      layout="vertical"
      initialValues={{ text, placeholder }}
      form={form}>
      <Form.Item label="标题" name="text">
        <Input />
      </Form.Item>
      <Form.Item label="placeholder" name="placeholder">
        <Input />
      </Form.Item>
    </Form>
  )
}

export default PropComponent
